import axios from 'axios';
import {
  deepCopyObj,
  copyObjBySelf,
  deepCopyObjArray
} from '../../../../assets/js/help.js'
export default {
  data() {
    var validateParkJson = (rule, value, callback) => {
      let self = this;
      if (!self.tableData.parkItems.length) {
        return callback(new Error('请选择支持的停车场'));
      }
      callback();
    };
    var today = [new Date(moment().format('YYYY-MM-DD 00:00:00')), new Date(moment().format('YYYY-MM-DD 23:59:59'))];
    return {
      isShowTree: true, //判断是不是有树的数据  再显示弹框是暂无数据还是显示树
      //显示及语音
      showMessage: null,
      showMessage_: {
        validInWarnOut: {
          carIn: {
            easy: {
              id: null,
              text: "%P\\%VM",
              voice: "%P%VM"
            },
            hard: {
              id: null,
              text: "%P\\%VM请稍候",
              voice: "%P%VM请稍候"
            }
          },
          carOut: {
            easy: {
              id: null,
              text: "%P\\%VM",
              voice: "%P%VM"
            },
            hard: {
              id: null,
              text: "%P\\%VM请稍候",
              voice: "%P%VM请稍候"
            }
          }
        },
        validInWarnIn: {
          carIn: {
            easy: {
              id: null,
              text: "%P\\剩余%VT天",
              voice: "%P剩余%VT天"
            },
            hard: {
              id: null,
              text: "%P\\剩余%VT天",
              voice: "%P剩余%VT天"
            }
          },
          carOut: {
            easy: {
              id: null,
              text: "%P\\剩余%VT天",
              voice: "%P剩余%VT天"
            },
            hard: {
              id: null,
              text: "%P\\剩余%VT天",
              voice: "%P剩余%VT天"
            }
          }
        },
        validOutDelIn: {
          carIn: {
            easy: {
              id: null,
              text: "%P\\%VM已过期",
              voice: "%P%VM已过期"
            },
            hard: {
              id: null,
              text: "%P\\%VM已过期",
              voice: "%P%VM已过期"
            }
          },
          carOutPay: {
            easy: {
              id: null,
              text: "%VM已过期\\应缴费%C元",
              voice: "%VM已过期应缴费%C元"
            },
            hard: {
              id: null,
              text: "%VM已过期\\应缴费%C元",
              voice: "%VM已过期应缴费%C元"
            }
          },
          carOutNoPay: {
            easy: {
              id: null,
              text: "%P\\%VM已过期",
              voice: "%P%VM已过期"
            },
            hard: {
              id: null,
              text: "%P\\%VM已过期",
              voice: "%P%VM已过期"
            }
          }
        }
      },
      //高级配置
      vipTypeData: {
        id: null,
        customVipName: '',
        settlementType: 0,
        settlementAmount: null,
        isDynamicMode: 0,
        dynamicCarportNumber: null,
        isDatePrivilege: 0,
        isTimePrivilege: 0,
        privilegeTimePeriod: null,
        isChargeGroupRelated: 0,
        chargeGroupCode: null,
        vipGroupType: 0,
        dynamicFullLimit: 0,
        dynamicCarNumber: null,
        vipNearExpiredDayThreshold: 10, //到期提醒时长天数
        vipDeleteExpiredDayThreshold: 0, //删除期天数
        openVipFullLimit: 0,
        vipFullLimitValue: '',
        vipFullOpenModel: 0,
        vipRecoverTime: null,
        priTimeArr: today,
        priTimeArrFrom: '', //开始时间
        priTimeArrTo: '', //结束时间
        priDateArrStr: '',
        parkId: '',
        parkName: '',
        channelAuthTree: '',
        channelSeqList: [],
      },
      mouthTicketData: {
        tabName: 'basicTab',
        ticketModalName: '',
        //基础信息
        baseTicketData: {
          id: '',
          parkSysType: '', //停车场类型
          vipGroupType: 2, //特殊车辆类型
          name: '', //类型名称
          description: '', //简介
          sellFromTo: [],
          validFromTo: [],
          validDateType: '',
          maxSellNum: '',
          financialParkId: '', //记录哪一个停车场为财务主体
          parkJson: [], //每条记录都记录 停车场的ID和对应的VIP类型的关系
          remark: '',
          sellingPic: '',
          selloutPic: '',
          sellingPicName: '',
          selloutPicName: '',
          renewFormerDays: 0,
          inviteCarTotal: 3,
          parkVipTypeJson: ''
        }
      },
      tableData: {
        parkItems: [], //通过停车场的ID请求到的停车场对应的VIP类型的列表
      },
      parkingLotUrl: '/vip/vipType/getChannelAuthTreeMultiPark.do', //停车场-通道数据url
      modalStatus: '', //模态框状态(1:创建;2:编辑基础信息、3:高级配置、4:显示及语音;5:查看)
      selectedParkingLot:'', //已选择的停车场树数据
      selectedParkingLotStr:'', //已选择停车场
      specialCarTypeObj : { //查看特殊车辆类型obj
        dialogVisible: false, //查看框是否显示
        tabName: '',
        basicData:{
          channelArr:[], //所选通道
          vipGroupTypeStr:'', //特殊车辆类型
          name: '', //类型名称
          description: '', //简介
        },
        superiorData:{
          moreCarMoreSeat: '', //是否支持多车多位
          autoSwitchVip: '', //是否支持场内切换
          dynamicFullLimit: '', //是否支持内场多位多车满位到剩余

          openVipFullLimit: '', //是否支持满位控制
          vipFullLimitValue: '', //最多可进多少辆车
          vipFullOpenModel: '', //满位放行模式

          isDatePrivilege: '', //是否按日期
          priDateArrStr: '', //已选择的日期

          isTimePrivilege: '', //是否按时间段
          timeSlot: '', //时间段

          iScharging: '', //是否计费
        }
      },
      allParkingTreeData:[], //所有停车场树数据
      parkingTreeDataUrl: '/vip/vipType/getChannelAuthTreeMultiPark.do', //获取停车场树数据接口url
      settings : {
        check: {
          enable: true,
          autoCheckTrigger: true,
          chkboxType: {
            "Y": "ps",
            "N": "ps"
          }
        },
        data: {
          key: {
            checked: "checked",
            chkDisabled: true,
            children: "childrenList",
          }
        },
        view: {
          showIcon: false,
          showLine: false,
        },
        callback: {
          onCheck: this.setChkDisabledEvent
        }
      },
      rules: {
        vipGroupType: [{
          required: true,
          message: '请选择特殊车辆类型'
        }],
        name: [{
            required: true,
            message: '类型名称不能为空',
            trigger: ['change','blur']
          },
          {
            min: 2,
            max: 200,
            message: '长度在 2 到 200 个字符',
            trigger: ['change','blur']
          }
        ],
        description: [
          {
            max: 200,
            message: '最多200 个字符',
            trigger: ['change','blur']
          }
        ],
        parkJson: [{
          validator: validateParkJson,
          trigger: ['change','blur']
        }],
        vipFullLimitValue: [{
            required: true,
            message: '请填写满位控制数量'
          },
          {
            type: 'number',
            message: '该字段必须为数字值',
            trigger: ['change','blur']
          }
        ],
        priTimeArr: [{
          required: true,
          message: '请选择时间段'
        }],
        priTimeArrFrom: [{
          required: true,
          message: '请选择开始时间'
        }],
        priTimeArrTo: [{
          required: true,
          message: '请选择结束时间'
        }],
      },
    }
  },
  watch: {
    'tableData.parkItems': function (newMouthTicketData) {
      if (this.$refs.ticketForm) {
        this.$refs.ticketForm.validateField('parkJson');
      }
    },
  },
  filters:{
    vipFullOpenModel: function(val){
      switch (val) {
        case 0:
          return '系统有空位自动放行，无空位手动放行按VIP计费';
        case 1:
          return '系统有空位自动放行，无空位手动放行按临时车计费';
        case 2:
          return '系统无空位自动放行，按临时车计费';
        default:
          break;
      }
    }
  },
  created() {
    this.getAllParkingTreeData()
    this.showMessage = deepCopyObj(this.showMessage_)
  },
  methods: {
    // 停车场树选项是否可以被选择
    setChkDisabledEvent(event, treeId, treeNode) {
      let treeObj = $.fn.zTree.getZTreeObj('ParkTree');
      let isChecked = treeNode.checked; //是否被选择
      let parkSysType = treeNode.parkSysType; //所属车场类型
      let parkingLotTreeNodes = treeObj.getNodes(); //所有的停车场节点
      let selectedNodes = treeObj.getCheckedNodes(true); //选择的节点
      let selectedNodesLength = selectedNodes.length;
      for (let i = 0; i < parkingLotTreeNodes.length; i++) {
        if (parkingLotTreeNodes[i].parkSysType !== parkSysType) {
          if (!isChecked) {
            //取消选择
            if (!selectedNodesLength) {
              //没有节点被选中
              treeObj.setChkDisabled(parkingLotTreeNodes[i], false, true, true);
            } else {
              treeObj.setChkDisabled(parkingLotTreeNodes[i], true, true, true);
            }
          } else {
            treeObj.setChkDisabled(parkingLotTreeNodes[i], true, true, true);
          }
        } else {
          treeObj.setChkDisabled(parkingLotTreeNodes[i], false, true, true);
        }
      }
    },
    // 获取vems停车场树数据
    fetchVemsParkingTreeData(){
      let params = {
        parkId: null,
        vipTypeId: null,
        parkSysType: 0,
        canCheckAll: 1
      };
      return API.fetchPost(this.parkingTreeDataUrl, params);
    },
    // 获取云停车场树数据
    fetchParkingTreeData(){
      let params = {
        parkId: null,
        vipTypeId: null,
        parkSysType: 1,
        canCheckAll: 1
      };
      return API.fetchPost(this.parkingTreeDataUrl, params);
    },
    // 获取所有停车场树数据
    getAllParkingTreeData(){
      let self = this
      axios.all([self.fetchVemsParkingTreeData(),self.fetchParkingTreeData()]).then(
        axios.spread((vems,parkingLot)=>{
          let treeDataArr = [];
          let vemsTreeArr = vems.data ? vems.data : [];
          let parkingLotTreeArr = parkingLot.data ? parkingLot.data : [];
          treeDataArr = vemsTreeArr.concat(parkingLotTreeArr);
          self.allParkingTreeData = deepCopyObjArray(treeDataArr)
        }) 
      )
    },
    // 判断是否只有一个停车场
    judgeHasOneParking(treeName){
      let self = this
      if(Array.isArray(self.allParkingTreeData) && self.allParkingTreeData.length===1){
        self.mouthTicketData.baseTicketData.parkSysType = self.allParkingTreeData[0].parkSysType
        self.selectedParkingLotStr = self.allParkingTreeData[0].name
        self.selectedParkingLot.push({
          name: self.allParkingTreeData[0].name,
        })
        $.fn.zTree.destroy(treeName);
        let treeObj = $.fn.zTree.init($("#"+treeName), self.settings, self.allParkingTreeData);
        let nodes = treeObj.getCheckedNodes(false) //获取全部节点
        self.vipTypeData.channelAuthTree = JSON.stringify(nodes);
        let childrenNodeArr = []
        nodes.forEach(elem=>{
          if(elem.parkId && elem.channelId){
            childrenNodeArr.push(elem)
          }
        })
        self.selectedParkingLot[0].children = childrenNodeArr
        let channelNode = nodes.find(elem=>{
          return elem.parkId && elem.channelId
        })
        self.tableData.parkItems.push({
          parkSysType: channelNode.parkSysType, 
          parkVipTypeId: "",
          parkLongId: channelNode.parkId,
          parkId: channelNode.parkUuid,
          parkName: channelNode.parkName,
          chargeGroupCode: '', //计费组编号
          optionArr: []
        });
        //查询计费组
        self.selectChargeGroupList();
      }
    },
    openCalendar() {
      this.toOpenModal('multiCalendarModal');
    },
    saveCalendar(calendar) {
      this.vipTypeData.priDateArrStr = calendar;
      this.closed('multiCalendarModal');
    },
    //创建特殊类型
    createConfig(title,type){
      var self = this;
      self.modalStatus = 1
      self.mouthTicketData.ticketModalName = title;
      self.mouthTicketData.tabName = 'basicTab'
      self.initMouthData_create();
      self.mouthTicketData.baseTicketData.vipGroupType = type
      self.judgeHasOneParking();
      self.toOpenModal('monthlyTicketModal')
      this.$nextTick(() => {
        this.$forceUpdate();
      });
    },
    initMouthData_create() {
      var self = this;
      self.showMessage = deepCopyObj(self.showMessage_);
      self.mouthTicketData.baseTicketData = {
        id: '',
        parkSysType: '',
        vipGroupType:'',
        name: '',
        description: '',
        sellFromTo: [],
        validFromTo: [],
        validDateType: '',
        maxSellNum: '',
        financialParkId: '',
        parkJson: [],
        remark: '',
        sellingPic: '',
        selloutPic: '',
        sellingPicName: '',
        selloutPicName: '',
        renewFormerDays: 0,
        inviteCarTotal: 3,
        parkVipTypeJson: ''
      };
      self.vipTypeData = {
        id: null,
        customVipName: '',
        settlementType: 0,
        settlementAmount: null,
        isDynamicMode: 0,
        dynamicCarportNumber: null,
        isDatePrivilege: 0,
        isTimePrivilege: 0,
        privilegeTimePeriod: null,
        isChargeGroupRelated: 0,
        chargeGroupCode: null,
        vipGroupType: 0,
        dynamicFullLimit: 0,
        dynamicCarNumber: null,
        vipNearExpiredDayThreshold: 10,
        vipDeleteExpiredDayThreshold: 0,
        openVipFullLimit: 0,
        vipFullLimitValue: '',
        vipFullOpenModel: 0,
        vipRecoverTime: null,
        priTimeArr: self.today,
        priTimeArrFrom: '', //开始时间
        priTimeArrTo: '', //结束时间
        priDateArrStr: '',
        parkId: '',
        parkName: '',
        channelAuthTree: '',
        channelSeqList: [],
      };
      this.tableData = {
        parkItems: [],
      };
      self.selectedParkingLot = []
      self.selectedParkingLotStr = ''
    },
    // 计费组
    selectChargeGroupList() {
      var self = this;
      if (self.tableData.parkItems) {
        let parkIdList = [];
        self.tableData.parkItems.forEach(function (item_) {
          parkIdList.push(item_.parkId);
        }, this);

        API.fetchGet('/park/specialCarTypeConfig/selectChargeGroupList2.do',{
            parkIdList: parkIdList.join(",")
          })
          .then(res2 => {
            var data = res2.data;
            var parkItems = self.tableData.parkItems;
            parkItems.forEach(function (parkItem) {
              parkItem.optionArr = [];
              let defaultOption = ''
              for(let key in data){
                if(key==parkItem.parkId){
                  let tmpArr = data[key];
                  for(let i = 0; i<tmpArr.length; i++){
                    tmpArr[i].chargeTypeSeq += ''
                    parkItem.optionArr.push(tmpArr[i]);
                    if(parkItem.chargeGroupCode!==0 && parkItem.chargeGroupCode!=='0' && !parkItem.chargeGroupCode){
                      defaultOption = tmpArr[i].chargeTypeSeq==0 ? tmpArr[i].chargeTypeSeq : defaultOption
                    }
                  }
                  if(parkItem.chargeGroupCode!==0 && parkItem.chargeGroupCode!=='0' && !parkItem.chargeGroupCode){
                    parkItem.chargeGroupCode = defaultOption;
                  }
                }
              }
            }, this);
            this.chargeGroupRender = false;
            this.$nextTick(()=>{
              this.chargeGroupRender = true
            })

          }, err2 => {});
      }
    },
    // 车辆分类-新增or编辑-tab切换
    selectMonthTicketInfoTab(tabName) {
      this.mouthTicketData.tabName = tabName;
    },
    // 月票类型-查看-tab切换
    selectMonthTicketCheckInfoTab(tabName) {
      this.specialCarTypeObj.tabName = tabName;
    },
    // 查看特殊车辆类型
    async checkSpecialCarType(params,type){
      let self = this
      self.clearSpecialCarTypeObj() //清空查看月票对象
      self.modalStatus = 5
      await self.fetchSpecialCarTypeData(params,type)
      self.toOpenModal('specialCarTypeCheck')
      this.$nextTick(() => {
        this.$forceUpdate();
      });
    },
    // 清空查看特殊车辆类型对象
    clearSpecialCarTypeObj(){
      this.specialCarTypeObj = {
        dialogVisible: false,
        tabName: '',
        basicData:{
          channelArr:[], //所选通道
          name: '', //类型名称
          vipGroupTypeStr:'', //特殊车辆类型
          description: '', //简介
        },
        superiorData:{
          moreCarMoreSeat: '', //是否支持多车多位
          autoSwitchVip: '', //是否支持场内切换
          dynamicFullLimit: '', //是否支持内场多位多车满位到剩余

          openVipFullLimit: '', //是否支持满位控制
          vipFullLimitValue: '', //最多可进多少辆车
          vipFullOpenModel: '', //满位放行模式

          isDatePrivilege: '', //是否按日期
          priDateArrStr: '', //已选择的日期

          isTimePrivilege: '', //是否按时间段
          timeSlot: '', //时间段

          iScharging: '', //是否计费
        }
      };
    },
    // 获取特殊车辆类型数据 type:1访客; type:2黑名单
    fetchSpecialCarTypeData(params,type){
      let self = this
      let url = type===1 ? '/park/parkVisitorlist/configDetail' : '/park/parkBlacklist/configDetail'
      return API.fetchGet(url,params).then(res=>{
        if(res.data){
          let data = res.data
          self.tableData.parkItems = []
          self.specialCarTypeObj.tabName = 'basicTab'
          self.specialCarTypeObj.basicData.name = data.name //类型名称
          self.specialCarTypeObj.basicData.vipGroupTypeStr = data.vipGroupType==1 ? '访客' : (data.vipGroupType==2 ? '黑名单' : '预定') // 特殊车辆类型
          self.specialCarTypeObj.basicData.description = data.description
          self.tableData.parkItems = [];
          let rowDataParkList = [];
          if(data.vipGroupType==2){ //黑名单
            rowDataParkList = data.blacklistConfigParkList;
          }else if(data.vipGroupType==1){ //访客
            rowDataParkList = data.visitorlistConfigParkList;
          }else{ //预定
            rowDataParkList = data.bookingConfigParkList
          }
          for (var i = 0; i < rowDataParkList.length; i++) {
            rowDataParkList[i].parkSysType = data.parkSysType
            self.tableData.parkItems.push(rowDataParkList[i])
          }
          // 查询计费组
          if(data.parkSysType===1){
            self.selectChargeGroupList();
          }
          if (data.channelArr) {
            let arr = {};
            for (let i = 0; i < data.channelArr.length; i++) {
              let node = data.channelArr[i]
              if(node.channelSeq && node.parkId){ //通道节点
                let parkName = node.parkName;
                let channelName = node.name;
                if (arr.hasOwnProperty(node.parkName)) {
                  arr[parkName].push(channelName);
                } else {
                  arr[parkName] = [];
                  arr[parkName].push(channelName);
                }
              }
            }
            for (let key in arr) {
              if (arr.hasOwnProperty(key)) {
                let obj = {
                  parkName: key,
                  channelName: arr[key].join('/')
                };
                self.specialCarTypeObj.basicData.channelArr.push(obj);
              }
            }
          }

          // 高级配置
          let parkVipType = data.parkVipType
          self.specialCarTypeObj.superiorData.moreCarMoreSeat = parkVipType.isDynamicMode==1 ? '支持' : '不支持' //多位多车
          self.specialCarTypeObj.superiorData.autoSwitchVip = parkVipType.autoSwitchVip==1 ? 1 : 0 //内场切换
          self.specialCarTypeObj.superiorData.dynamicFullLimit = parkVipType.dynamicFullLimit==1 ? 1 : 0
          self.specialCarTypeObj.superiorData.openVipFullLimit = parkVipType.openVipFullLimit==1 ? '支持' : '不支持' //满位控制
          self.specialCarTypeObj.superiorData.vipFullLimitValue = parkVipType.vipFullLimitValue ? parkVipType.vipFullLimitValue : 0 //最多可进
          self.specialCarTypeObj.superiorData.vipFullOpenModel = parkVipType.vipFullOpenModel //满位放行模式
          self.specialCarTypeObj.superiorData.isDatePrivilege = parkVipType.isDatePrivilege==1 ? '支持' : '不支持' //按日期
          self.specialCarTypeObj.superiorData.priDateArrStr = parkVipType.priDateArrStr; //日期控件数据
          self.specialCarTypeObj.superiorData.isTimePrivilege = parkVipType.isTimePrivilege == 1 ? '支持' : '不支持'; //是否时间段
          self.specialCarTypeObj.superiorData.timeSlot = parkVipType.privilegeTimePeriod; //时间段
          self.specialCarTypeObj.superiorData.iScharging = parkVipType.isChargeGroupRelated == 1 ? '是' : '否'; //是否计费
        }
      })
    },
    openSelectParkModal() {
      var _this = this;
      _this.toOpenModal('selectParkModal');
      setTimeout(_this.initChannelTree,500,"ParkTree");
    },
    async initChannelTree(treeName, rowParam) {
      let self = this;
      let params,nodes;
      if(rowParam){
        self.selectParkModalStatus = 0 //停车场树选择框-确认按钮
        params = {
          id: rowParam.id
        };
        nodes = await self.fetchConfigParkChannels(params)
      }else{
        self.selectParkModalStatus = 1 //停车场树选择框-确认按钮
        nodes = deepCopyObjArray(self.allParkingTreeData) 
      }
      $.fn.zTree.destroy(treeName);
      this.isShowTree = true;
      if (!nodes || nodes.length==0) {
        this.isShowTree = false
        return;
      }
      let treeObj = $.fn.zTree.init($("#ParkTree"), self.settings, []);
      //每次都从数据库获取通道的信息，然后从已保存的channelAuthTree中checked
      if (self.vipTypeData.channelAuthTree && self.vipTypeData.channelAuthTree!='') {
        var selectTreeNodes = JSON.parse(self.vipTypeData.channelAuthTree); //已选的通道节点
        var treeNodes = nodes; //全部节点
        var simpleNodesArray = treeObj.transformToArray(treeNodes); //将全部节点转为普通对象
        for (var i = 0; i < simpleNodesArray.length; i++) {
          var simpleNode = simpleNodesArray[i];
          for (var j = 0; j < selectTreeNodes.length; j++) {
            var treeNode = selectTreeNodes[j];
            if (simpleNode.parkId &&
              simpleNode.channelSeq &&
              treeNode.areaId == simpleNode.areaId &&
              treeNode.parkId == simpleNode.parkId &&
              treeNode.channelSeq == simpleNode.channelSeq) {
              simpleNode.checked = true;
              break;
            }
          }
        }
        nodes = treeNodes;
      }
      treeObj.addNodes(null, 0, nodes);

      //勾选父节点的操作
      var temp_checkNodes = treeObj.getCheckedNodes();
      temp_checkNodes.forEach(function(t) {
        if(!t.hasChildren){
          treeObj.checkNode(t,true,true);
        }
      }, this);

      treeObj.expandAll(true);
    },
     // 获取已选择的停车场通道数据
    fetchConfigParkChannels(params){
      let self = this
      return new Promise((resolve, reject)=>{
        API.fetchPost('/park/specialCarTypeConfig/getConfigParkChannels.do',params).then(res=>{
          resolve(res.data)
        },err=>{})
      })
    },
    // modal弹框--选择停车场时确认时调用函数
    selectParkSure() {
      var self = this,
        nodes = [];
      var params = deepCopyObj(self.vipTypeData);
      var treeObj = $.fn.zTree.getZTreeObj("ParkTree");
      nodes = treeObj.getCheckedNodes(true); // 获取tree被勾选的节点

      //通道信息json
      params.channelAuthTree = JSON.stringify(nodes);
      self.vipTypeData.channelAuthTree = JSON.stringify(nodes);
      let parkList = new Array();
      let selectedParkListTmp = []

      for (var i = 0; i < nodes.length; i++) {
        //过滤重复的停车场，只有通道才有parkId值
        var node = nodes[i];
        if(node.parkId){
          parkList[node.parkId] = node;
          // 以停车场为单位进行组合
          if(selectedParkListTmp.hasOwnProperty(node.parkName)){
            selectedParkListTmp[node.parkName].push(node)
          }else{
            selectedParkListTmp[node.parkName] = []
            selectedParkListTmp[node.parkName].push(node)
          }
        }
      }
      if (parkList.length <= 0) {
        self.showToast('请选择至少一个通道', 0);
        return;
      }
      self.mouthTicketData.baseTicketData.parkSysType = nodes[0].parkSysType
      // 初始化表格显示数据以及提交的表格参数
      self.tableData = {
        parkItems: []
      };
      self.selectedParkingLot = []
      self.selectedParkingLotStr = ''
      self.mouthTicketData.baseTicketData.parkJson = [];
      let itemobjArr = [];
      let selectedParkingLotStrArr = []
      for (let key in parkList) {
        if (parkList.hasOwnProperty(key)) {
          itemobjArr.push({
            parkSysType: parkList[key].parkSysType, 
            parkVipTypeId: "",
            parkLongId: parkList[key].parkId,
            parkId: parkList[key].parkUuid,
            parkName: parkList[key].parkName,
            chargeGroupCode: parkList[key].chargeGroupCode,
            optionArr: []
          });
          selectedParkingLotStrArr.push(parkList[key].parkName)
        }
      }
      for(let key in selectedParkListTmp){
        if(selectedParkListTmp.hasOwnProperty(key)){
          self.selectedParkingLot.push({
            parkId: selectedParkListTmp[key][0].parkId,
            name: selectedParkListTmp[key][0].parkName,
            open: true,
            children: selectedParkListTmp[key]
          })
        }
      }
      self.selectedParkingLotStr = selectedParkingLotStrArr.join('/')
      self.closed('selectParkModal');
      self.tableData.parkItems = itemobjArr;
      //查询计费组
      if(self.mouthTicketData.baseTicketData.parkSysType===1){
        self.selectChargeGroupList();
      }
      this.$nextTick(() => {
        this.$forceUpdate();
      });
    },
    // 获取特殊车辆类型名称列表
    getVisitorConfigList(){
      this.$emit('getVisitorConfigList','addNew')
    },
    submitForm(formName) {
      var self = this;
      this.$refs[formName].validate((valid) => {
          if (valid) {
            self.saveTicket();
          } else {
            return false;
          }
      })
    },
    // 保存月票时调用函数
    saveTicket() {
      var self = this;
      if(self.vipTypeData.isChargeGroupRelated){ //计费
        if(Array.isArray(self.tableData.parkItems) && self.tableData.parkItems[0].parkSysType===0){
          for(let i = 0; i<self.tableData.parkItems.length; i++){
            let elem = self.tableData.parkItems[i]
            if(!elem.chargeGroupCode){
              self.showToast('请填写计费组编号',0,1500);
              return;
            }
            if(!/^[0-9]+$/.test(elem.chargeGroupCode)){
              self.showToast('计费组编号只能输入数字',0,1500);
              return;
            }
          }
        }
      }

      var params = deepCopyObj(self.mouthTicketData.baseTicketData);

      params['parkJson'] = JSON.stringify(self.tableData.parkItems);
      var vipTypeData_ = deepCopyObj(self.vipTypeData);

      //收费组
      if (self.vipTypeData.isChargeGroupRelated == 0) {
        vipTypeData_.chargeGroupCode = null;
      }

      // 按日期
      if(self.vipTypeData.isDatePrivilege && !self.vipTypeData.priDateArrStr){
        self.showToast('请选择区分日期', 0);
        return;
      }

      //区分时间段
      if (self.vipTypeData.isTimePrivilege && self.vipTypeData.priTimeArrFrom instanceof Date && self.vipTypeData.priTimeArrTo instanceof Date) {
        vipTypeData_.privilegeTimePeriod = self.vipTypeData.priTimeArrFrom.Format("hh:mm") + "-" + self.vipTypeData.priTimeArrTo.Format("hh:mm");
      } else {
        vipTypeData_.privilegeTimePeriod = '';
      }

      if (self.vipTypeData.isTimePrivilege && vipTypeData_.privilegeTimePeriod == '') {
        self.showToast('请选择区分时间段范围', 0);
        return;
      }

      params.parkVipTypeJson = JSON.stringify(vipTypeData_);
      params['showMessage'] = JSON.stringify(self.showMessage);

      API.operation.specialCarTypeConfigAdd(params).then(res => {
        var data = res;
        console.log(res)
        if (data.status == 1) {
          self.showToast('创建成功', 1);
          self.closed('monthlyTicketModal')
          self.getVisitorConfigList()
        } else {
          self.showToast(data.message, 2);
        }
      }, err => {});
    },
  },
}